﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebStudio.Business.Rule;

public partial class Admin_Login : System.Web.UI.Page
{
    static string sValidator = "";
    private readonly string sValidatorImageUrl = "ValidateImage.aspx?Validator=";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            sValidator = GetRandomint();
            ValidateImage.ImageUrl = sValidatorImageUrl + sValidator;
        }
    }

    private String GetRandomint()
    {
        Random random = new Random();
        return (random.Next(100000, 999999).ToString());
    }

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        if (Page.IsValid)
        {
            if (sValidator == Code.Text.ToString())
            {
                bool isLogin = UserRule.IsLogin(UserName.Text.Trim(), PassWord.Text.Trim());
                //bool isLogin = true;
                if (isLogin)
                {
                    Session["Admin_User"] = UserName.Text.ToString();
                    Response.Write("<script>alert('欢迎您" + UserName.Text.Trim().ToString() + "登录成功');location.href='Default.aspx';</script>");
                }
                else
                {
                    Response.Write("<script>alert('账号或密码错误');location.href='login.aspx';</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('验证码错误');location.href='login.aspx';</script>");
            }
        }
    }
}
